﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace MX.Core.Http.WebAction
{
    /// <summary>
    /// cookie管理器， 负责维护cookie，实现cookie的可控
    /// </summary>
    public class CookieManager
    {
        CookieContainer container = new CookieContainer();
        public void SetCookie(string cookie, string url)
        {
            container.SetCookies(new Uri("http://" + url), cookie);
        }

        public string GetCookieHeader(string host)
        {
            return container.GetCookieHeader(new Uri("http://" + host));
        }

        public CookieCollection GetCookies(string host)
        {
            return container.GetCookies(new Uri("http://" + host));
        }

        public string GetCookieHeader(Uri uri)
        {
            return container.GetCookieHeader(uri);
        }

        public void SetCookie(string cookie, Uri uri)
        {
            container.SetCookies(uri, cookie);
        }
    }
}
